home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 203 < prev    next >
Text File  |  1996-08-06  |  9KB  |  210 lines

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++,comp.lang.c,comp.std.c
  4. Subject: Re: Hungarian notation
  5. Date: Sat, 27 Jan 1996 14:21:46 GMT
  6. Organization: Netcom
  7. Message-ID: <310a2c36.51792576@nntp.ix.netcom.com>
  8. References: <30C40F77.53B5@swsbbs.com> <4d2ok0$69s@beach.and.nl> <4dtv3gINNo9u@keats.ugrad.cs.ubc.ca> <SPENCER.96Jan22113215@zorgon.ERA.COM> <4e1nd8$hv0@solutions.solon.com> <3104bfc8.132251392@nntp.ix.netcom.com> <dewar.822407919@schonberg> <3106260f.224013120@nntp.ix.netcom.com> <4e6oj9$o02@news.xmission.com> <31077335.52859072@nntp.ix.netcom.com> <JSA.96Jan25190824@organon.com> <310842ad.6002240@nntp.ix.netcom.com> <JSA.96Jan26175507@organon.com> <31098190.8106176@nntp.ix.netcom.com> <4eco1g$aih@fountain.mindlink.net>
  9. NNTP-Posting-Host: ix-dc6-22.ix.netcom.com
  10. X-NETCOM-Date: Sat Jan 27  6:21:52 AM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. genew@mindlink.bc.ca (Gene Wirchenko) wrote:
  14.  
  15. > miker3@ix.netcom.com (Mike Rubenstein) wrote:
  16. > >jsa@organon.com (Jon S Anthony) wrote:
  17. > >NOTE:  I've removed all groups from this posting except comp.lang.c
  18. > >and comp.lang.c++ and have added cmp.std.c
  19. > >Since I've added a new group, let me summarize a bit.  The discussion
  20. > >revolves around the result of converting a signed integral type to a
  21. > >smaller type when the value in the original cannot be represented in
  22. > >the new type.
  23. > >I claim that ISO 6.2.1.2 requires that an implementation actually do
  24. > >such a conversion.  The implementor may choose the mapping.  Beside
  25. > >the usual throwing away of high order bits, possibilities include
  26. > >always using the value 0, or the largest possible value for the new
  27. > >type, or, even, a random value.
  28. >      Or even a random value for your system disk <G>.
  29. >      Implementation defined means implementation defined, not what you
  30. > want it to mean.  I agree that your interpretation sets out reasonable
  31. > actions that might be performed.  Please quote chapter and verse on
  32. > where the Standard states that implementation defined actions must be
  33. > "reasonable" (whatever the hell that is <G>).
  34. > >However, I claim that a conversion is required -- the implementation
  35. > >must come up with a value that can be represented in the new type and
  36. > >use that.  It may not do other things like, as one person claimed,
  37. > >deleting the system disk even if such action is documented.
  38. >      Is your claim supported in the Standard?  If it isn't, you're
  39. > wasting your time.  What if the conversion results in overflow?
  40. > >> In article <310842ad.6002240@nntp.ix.netcom.com> miker3@ix.netcom.com (Mike Rubenstein) writes:
  41. > >> 
  42. > >> > jsa@organon.com (Jon S Anthony) wrote:
  43. > >> > 
  44. > >> > > In article <31077335.52859072@nntp.ix.netcom.com> miker3@ix.netcom.com (Mike Rubenstein) writes:
  45. > >> > > 
  46. > >> > > > I think you're reading something into my post that isn't there.
  47. > >> > > > 
  48. > >> > > > What am I reading into the standard that's not there?  Nothing in my
  49. > >> > > > post suggests that defining the result as always 0 is illegal.  In
  50. > >> > > > fact, it is clearly legal.
  51. > >> > > > 
  52. > >> > > > But the standard does impose some restrictions on the definition.  The
  53. > >> > > > definition must specify that the subject type is converted to the
  54. > >> > > > object type.  It must not produce side-effects.
  55. >      Why are no side effects permitted?  Chapter and verse, please.
  56.  
  57. For the same reason an implementation is not permitted to introduce
  58. side effects into the expression 1 + 2.  The standard defines the
  59. result as a conversion and that is what must be done -- nothing else
  60. may be done (that is detectable by a conforming program).
  61.  
  62. According to ISO 1,
  63.  
  64.     This International Standard specifies the form and establishes
  65.  
  66.     the interpretation of programs written in the C programming 
  67.     language.  It specifies
  68.  
  69.     ...
  70.  
  71.     - the semantic rules for interpretting C programs;
  72.  
  73. Where the standard specifies a conversion, I have the right to expect
  74. a conversion and not any other action.
  75.  
  76. > >> > > > 
  77. > >> > > > Please reread my post; I was responding to the statement that the
  78. > >> > > > definition could be to delete the system disk.  That is out of bounds
  79. > >> > > > for the definition and I said so.  I did not say that defining the
  80. > >> > > > result to be 0 is out of bounds.
  81. > >> > > 
  82. > >> > > Face it.  You just plain got it wrong.  Deleting the system disk is
  83. > >> > > perfectly within bounds.  Stupid, for sure, as no one in their right
  84. > >> > > mind would use such a compiler, but perfectly legal.
  85. > >> > 
  86. > >> > Please cite anything in the standard that supports your position.  I
  87. > >> > can find nothing in the standard that gives an implementation that
  88. > >> > license.
  89. >      If "implementation defined" does not qualify as "that licence",
  90. > what in your eyes would? 
  91.  
  92. Undefined behavior.  Implementation-defined behavior in a situation in
  93. which the standard does not impose requirments.
  94.  
  95. Implementation-defined behavior occurs for correct constructs with
  96. correct data (ISO 3.11).  It does not free the compiler from the
  97. obligation of complying with the requirements of the standard.
  98.  
  99. > >> > 
  100. > >> > Insults do not prove a point -- quotes from the standard do.  I've
  101. > >> > shown the passages that support my position.
  102. > >> 
  103. > >> I don't see any insult here at all.  Sorry if you took it that way.
  104. > >> 
  105. > >> Here's the relevant passage yet again:
  106. > >> 
  107. > >>      When a value with integral type is demoted to a signed integer
  108. > >>      with smaller size or an unsigned integer is converted to its 
  109. > >>      corresponding signed integer, if the value cannot be 
  110. > >>      represented the result is implementation defined.
  111. > >> 
  112. > >> Now, the problem is (as James Kanze has pointed out) that the term
  113. > >> "result" which you believe to know the "correct" definition of, is not
  114. > >> defined.  Because of this it _could_ be taken as meaning "result of
  115. > >> the computation".  You take it as a given that it means "result of the
  116. > >> expression", i.e., its value.  But that is not clear, and so an
  117. > >> interpretation given the former reading would indeed allow for
  118. > >> virtually any sort of behavior as long as that behavior was
  119. > >> documented.  As James Kanze pointed out, a very _reasonable_
  120. > >> interpretation given this reading of "result" would be to to signal
  121. > >> (raise) an exception.
  122. >      Agreed and this is what is keeping this argument going, eh?
  123. > >I've not seen Jame's post, but I look forward to seeing it.
  124. > >But, I don't see how the standard permits throwing an exception.  ISO
  125. > >6.2 says
  126. > >    Several operators convert operand values from one type to 
  127. > >    another automatically.  This subclause specifies the result 
  128. > >    required from such an implicit conversion, as well as those 
  129. > >    that result from a cast operation (an explicit conversion).
  130. >      What if the conversion results in overflow?
  131. > >It seems obvious to me that if one uses correctly a construction that
  132. > >the standard says converts a value from one type to another, then the
  133. > >implementation must convert the value from one type to another -- it
  134. > >may not do other things.  By definition (ISO 3.10)
  135. > >implementation-defined behavior only applies to a correct program
  136. > >construct and correct data.
  137. >      If it is impossible to convert due to sizing, then the "must" is
  138. > rather silly, isn't it?
  139. >      Would not the normal situation (especially since the point hasn't
  140. > been raised previously) imply that the conversion we want done applies
  141. > to a correct program construct and correct data?  Why would you assume
  142. > anything else?  You are permitted to answer that you may do as you
  143. > please because your assumptions are implementation defined <G>.
  144. >  
  145. > >I'm glad you intended no insult.  I'm afraid I just don't react well
  146. > >to ex cathedra statements that I am wrong, particularly when I have
  147. > >taken  care to give clear citations that I believe support my
  148. > >position.
  149. >      Yes, but you keep saying "claim" and write as if you are the
  150. > Right Hand of God.  So what about your claims!  If they can't be
  151. > supported by the Standard, forget it.  Schildt CLAIMS that void main()
  152. > is ok.
  153.  
  154. The fact that something is implementation defined does not free the
  155. compiler from the obligation of complying with the standard.  
  156.  
  157. Let's take a simple example.  Consider a machine with 8 bit characters
  158. and the program
  159.  
  160.     #include <stdio.h>
  161.     int main(void)
  162.     {
  163.        char c = (char) 256;
  164.       printf("%d\n", c);
  165.       return 0;
  166.     }
  167.  
  168. From ISO 6.3.4,
  169.  
  170.     Preceding an expression by a parenthesized type name converts 
  171.     the value of the expression to the named type.
  172.  
  173. Here I have a correct construct (it meets the syntax and constraint
  174. requirements of the standard) used with valid data.  No matter what, I
  175. have the right to expect the semantics defined by the standard --
  176. converting 256 to char -- will be implmented by the compiler.
  177.  
  178. The standard does not require the conversion to be reasonable
  179. (whatever that means), but it does require a conversion.  Since this
  180. is a conforming program, I have the right to expect that the
  181. implementation will comply with the semantics required by the
  182. standard.  The standard says that this program converts 256 to a char,
  183. prints the char as a decimal number, and terminates execution with a
  184. successful indication to the host.
  185.  
  186.  
  187. Michael M Rubenstein
  188.